package wds

import (
	"fmt"
	"pool"
	"net/http"
	"encoding/json"
	"labix.org/v2/mgo/bson"
)

/*
返回某个关键词的所有信息
*/
func Search(w http.ResponseWriter, r *http.Request) {

	r.ParseForm();

	if len(r.PostForm["wd"]) < 1 {
		return
	}

	wd := r.PostForm["wd"][0]
	// fmt.Println("wd:", wd)

	resD := []bson.M{}

	db := <-pool.MongoDB
	c := db.C("words")
	c.Find(bson.M{"wd": wd}).Select(bson.M{"uid": 0, "wd": 0}).All(&resD)
	
	pool.MongoDB <- db
	resB, _ := json.Marshal(resD)
	res := string(resB)
	fmt.Fprintf(w, "%s", res)
}
